package com.bss.search;

import java.util.List;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bss.dao.PatientDao;
import com.bss.model.Patient;

@Service
public class SearchService {

	private DataModel patientsDatamodel;

	@Autowired
	private PatientDao patientDao;

	public DataModel getPatients() {
		return this.patientsDatamodel;
	}

	@Transactional
	public DataModel getPatients(final String patientName) {
		List<Patient> patients = this.patientDao.find("firstName like '" + patientName + "%' order by firstName asc");
		this.patientsDatamodel = new ListDataModel(patients);
		return this.patientsDatamodel;
	}
}
